//
//  CustomizationViewControl.m
//  ai2ban
//
//  Created by Heartbeats on 2018/1/11.
//  Copyright © 2018年 mac book pro. All rights reserved.
//

#import "CustomizationViewControl.h"
#import "CustomizationCell.h"
#import "CustomizaOrderConfirmControl.h"
#import "GoodInfoController.h"

@interface CustomizationViewControl ()<UITableViewDelegate, UITableViewDataSource>
@property(nonatomic, strong) UITableView *tableView;
@property(nonatomic, strong) NSArray<JiFenGoodModel *> *goods;
@end

@implementation CustomizationViewControl

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"为你定制";
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"CustomizationCell" bundle:nil] forCellReuseIdentifier:@"CustomizationCell"];
    [self.view addSubview:self.tableView];
    [self getData];
}

- (void) getData {
    NSDictionary *param = @{@"offset": @"0", @"limit": @"100"};
    [[NetworkManager shareNetwork] requestWithURLString:@"app/system/getCustomizelist" parameters:param method:@"" callBack:^(id responseObject) {
        if ([responseObject[@"state"]intValue]) {
            self.goods = [JiFenGoodModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
            [self.tableView reloadData];
        }
        return;
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.goods.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    CustomizationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomizationCell" forIndexPath:indexPath];
    cell.goodModel = self.goods[indexPath.item];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (![AppManager userIsLogin]) {
        [self goToLogin];
        return;
    }
    GoodInfoController *goodInfoController = [[GoodInfoController alloc] init];
    goodInfoController.goodModel = self.goods[indexPath.row];
    [self.navigationController pushViewController:goodInfoController animated:true];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 200;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
